package com.market.service.impl;

import com.market.dto.ShopCartDto;
import com.market.entity.ShopCart;
import com.market.mapper.ShopCartMapper;
import com.market.service.ShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ShopCartServiceImpl implements ShopCartService {
    @Autowired
    private ShopCartMapper shopCartMapper;

    @Override
    public boolean addShopCartRecord(ShopCart shopCart) {
        int cart = shopCartMapper.addShopCart(shopCart);
        if (cart==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteShopCartRecord(int buyerId, int goodsId) {
        int i = shopCartMapper.deleteShopCart(buyerId, goodsId);
        if (i==1){
            return true;
        }
        return false;
    }


    @Override
    public boolean addShopCartNums(int buyerId, int goodsId) {
        int nums = shopCartMapper.addShopCartNums(buyerId, goodsId);
        if (nums==1){
            return true;
        }
        return false;
    }


    @Override
    public boolean reduceShopCartNums(int buyerId, int goodsId) {

        int nums = shopCartMapper.reduceShopCartNums(buyerId, goodsId);
        if (nums==1){
            return true;
        }
        return false;
    }

    @Override
    public List<ShopCartDto> findMyShopCart(int buyerId) {
        List<ShopCartDto> shopCarts = shopCartMapper.selectShopCartByBuyerId(buyerId);
        return shopCarts;
    }

    @Override
    public boolean updateShopCart(int nums, int buyerId, int goodsId) {
        if (nums<=0){
            return false;
        }
        return shopCartMapper.updateShopCartNums(buyerId,goodsId,nums)==1;
    }
}
